{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 游戏付费分析"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 数据读取"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "import warnings\n",
    "warnings.filterwarnings(\"ignore\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "data = pd.read_excel('付费分析v1.0.xlsx')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>玩家id</th>\n",
       "      <th>注册时间</th>\n",
       "      <th>付费时间</th>\n",
       "      <th>付费额度</th>\n",
       "      <th>计费点id</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>1.99</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>9.99</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-16</td>\n",
       "      <td>29.99</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-16</td>\n",
       "      <td>19.99</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-16</td>\n",
       "      <td>24.99</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   玩家id        注册时间        付费时间   付费额度  计费点id\n",
       "0     1  2019-11-15  2019-11-15   1.99      3\n",
       "1     1  2019-11-15  2019-11-15   9.99      1\n",
       "2     1  2019-11-15  2019-11-16  29.99      3\n",
       "3     1  2019-11-15  2019-11-16  19.99      3\n",
       "4     1  2019-11-15  2019-11-16  24.99      3"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 数据预处理"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "data['注册时间']= pd.to_datetime(data['注册时间'])\n",
    "data['付费时间']=pd.to_datetime(data['付费时间'])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 逻辑异常数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "6"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "((data['注册时间']>data['付费时间'])*1).sum()\n",
    "#存在错误数据，注册时间大于付费时间的有6组数据。需要选出。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>玩家id</th>\n",
       "      <th>注册时间</th>\n",
       "      <th>付费时间</th>\n",
       "      <th>付费额度</th>\n",
       "      <th>计费点id</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>25774</th>\n",
       "      <td>819</td>\n",
       "      <td>2019-09-20</td>\n",
       "      <td>2019-08-12</td>\n",
       "      <td>29.99</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25775</th>\n",
       "      <td>819</td>\n",
       "      <td>2019-09-20</td>\n",
       "      <td>2019-08-12</td>\n",
       "      <td>29.99</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25776</th>\n",
       "      <td>819</td>\n",
       "      <td>2019-09-20</td>\n",
       "      <td>2019-08-12</td>\n",
       "      <td>29.99</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25777</th>\n",
       "      <td>819</td>\n",
       "      <td>2019-09-20</td>\n",
       "      <td>2019-08-12</td>\n",
       "      <td>29.99</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26798</th>\n",
       "      <td>852</td>\n",
       "      <td>2019-10-03</td>\n",
       "      <td>2019-09-11</td>\n",
       "      <td>9.99</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31665</th>\n",
       "      <td>987</td>\n",
       "      <td>2019-11-07</td>\n",
       "      <td>2019-09-11</td>\n",
       "      <td>29.99</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       玩家id       注册时间       付费时间   付费额度  计费点id\n",
       "25774   819 2019-09-20 2019-08-12  29.99      3\n",
       "25775   819 2019-09-20 2019-08-12  29.99      3\n",
       "25776   819 2019-09-20 2019-08-12  29.99      3\n",
       "25777   819 2019-09-20 2019-08-12  29.99      3\n",
       "26798   852 2019-10-03 2019-09-11   9.99      3\n",
       "31665   987 2019-11-07 2019-09-11  29.99      3"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.loc[data['注册时间']>data['付费时间']]#=data.loc[data['注册时间']>data['付费时间'],'付费时间']\n",
    "#把付费时间赋值给注册时间"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "data.loc[data['玩家id']==819,'注册时间']=data.loc[data['玩家id']==819,'付费时间'].min()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "data.loc[data['玩家id']==852,'注册时间']=data.loc[data['玩家id']==852,'付费时间'].min()\n",
    "data.loc[data['玩家id']==987,'注册时间']=data.loc[data['玩家id']==987,'付费时间'].min()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>玩家id</th>\n",
       "      <th>注册时间</th>\n",
       "      <th>付费时间</th>\n",
       "      <th>付费额度</th>\n",
       "      <th>计费点id</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>31648</th>\n",
       "      <td>987</td>\n",
       "      <td>2019-09-11</td>\n",
       "      <td>2019-11-12</td>\n",
       "      <td>19.99</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31649</th>\n",
       "      <td>987</td>\n",
       "      <td>2019-09-11</td>\n",
       "      <td>2019-11-12</td>\n",
       "      <td>0.99</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31650</th>\n",
       "      <td>987</td>\n",
       "      <td>2019-09-11</td>\n",
       "      <td>2019-11-12</td>\n",
       "      <td>0.99</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31651</th>\n",
       "      <td>987</td>\n",
       "      <td>2019-09-11</td>\n",
       "      <td>2019-11-12</td>\n",
       "      <td>0.99</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31652</th>\n",
       "      <td>987</td>\n",
       "      <td>2019-09-11</td>\n",
       "      <td>2019-11-13</td>\n",
       "      <td>3.99</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31653</th>\n",
       "      <td>987</td>\n",
       "      <td>2019-09-11</td>\n",
       "      <td>2019-11-13</td>\n",
       "      <td>2.99</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31654</th>\n",
       "      <td>987</td>\n",
       "      <td>2019-09-11</td>\n",
       "      <td>2019-11-13</td>\n",
       "      <td>1.99</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31655</th>\n",
       "      <td>987</td>\n",
       "      <td>2019-09-11</td>\n",
       "      <td>2019-11-13</td>\n",
       "      <td>2.99</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31656</th>\n",
       "      <td>987</td>\n",
       "      <td>2019-09-11</td>\n",
       "      <td>2019-11-18</td>\n",
       "      <td>3.99</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31657</th>\n",
       "      <td>987</td>\n",
       "      <td>2019-09-11</td>\n",
       "      <td>2019-11-18</td>\n",
       "      <td>2.99</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31658</th>\n",
       "      <td>987</td>\n",
       "      <td>2019-09-11</td>\n",
       "      <td>2019-11-07</td>\n",
       "      <td>4.99</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31659</th>\n",
       "      <td>987</td>\n",
       "      <td>2019-09-11</td>\n",
       "      <td>2019-11-07</td>\n",
       "      <td>0.99</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31660</th>\n",
       "      <td>987</td>\n",
       "      <td>2019-09-11</td>\n",
       "      <td>2019-11-07</td>\n",
       "      <td>9.99</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31661</th>\n",
       "      <td>987</td>\n",
       "      <td>2019-09-11</td>\n",
       "      <td>2019-11-07</td>\n",
       "      <td>2.99</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31662</th>\n",
       "      <td>987</td>\n",
       "      <td>2019-09-11</td>\n",
       "      <td>2019-11-07</td>\n",
       "      <td>0.99</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31663</th>\n",
       "      <td>987</td>\n",
       "      <td>2019-09-11</td>\n",
       "      <td>2019-11-09</td>\n",
       "      <td>0.99</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31664</th>\n",
       "      <td>987</td>\n",
       "      <td>2019-09-11</td>\n",
       "      <td>2019-11-09</td>\n",
       "      <td>0.99</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31665</th>\n",
       "      <td>987</td>\n",
       "      <td>2019-09-11</td>\n",
       "      <td>2019-09-11</td>\n",
       "      <td>29.99</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       玩家id       注册时间       付费时间   付费额度  计费点id\n",
       "31648   987 2019-09-11 2019-11-12  19.99      1\n",
       "31649   987 2019-09-11 2019-11-12   0.99      2\n",
       "31650   987 2019-09-11 2019-11-12   0.99      2\n",
       "31651   987 2019-09-11 2019-11-12   0.99      2\n",
       "31652   987 2019-09-11 2019-11-13   3.99      3\n",
       "31653   987 2019-09-11 2019-11-13   2.99      2\n",
       "31654   987 2019-09-11 2019-11-13   1.99      3\n",
       "31655   987 2019-09-11 2019-11-13   2.99      2\n",
       "31656   987 2019-09-11 2019-11-18   3.99      3\n",
       "31657   987 2019-09-11 2019-11-18   2.99      1\n",
       "31658   987 2019-09-11 2019-11-07   4.99      2\n",
       "31659   987 2019-09-11 2019-11-07   0.99      2\n",
       "31660   987 2019-09-11 2019-11-07   9.99      2\n",
       "31661   987 2019-09-11 2019-11-07   2.99      2\n",
       "31662   987 2019-09-11 2019-11-07   0.99      2\n",
       "31663   987 2019-09-11 2019-11-09   0.99      2\n",
       "31664   987 2019-09-11 2019-11-09   0.99      2\n",
       "31665   987 2019-09-11 2019-09-11  29.99      3"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.loc[data['玩家id']==987]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 按照付费时间重新排序"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "data1 = data.sort_values(by = ['玩家id','付费时间']).reset_index(drop=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 构造“What”维度"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 首天付费"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>玩家id</th>\n",
       "      <th>付费时间</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>2019-08-13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>2019-12-03</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>2019-11-25</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>2019-08-11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>6</td>\n",
       "      <td>2019-08-04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>7</td>\n",
       "      <td>2019-03-24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>8</td>\n",
       "      <td>2019-08-07</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>9</td>\n",
       "      <td>2019-06-14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>10</td>\n",
       "      <td>2019-01-09</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>11</td>\n",
       "      <td>2019-09-26</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>12</td>\n",
       "      <td>2019-06-18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>13</td>\n",
       "      <td>2019-11-10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>14</td>\n",
       "      <td>2019-12-28</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>15</td>\n",
       "      <td>2019-11-16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>16</td>\n",
       "      <td>2019-09-24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>17</td>\n",
       "      <td>2019-10-19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>18</td>\n",
       "      <td>2019-07-19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>19</td>\n",
       "      <td>2019-08-05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>20</td>\n",
       "      <td>2019-04-12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>21</td>\n",
       "      <td>2019-10-18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>22</td>\n",
       "      <td>2019-08-16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>23</td>\n",
       "      <td>2019-10-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>24</td>\n",
       "      <td>2019-04-06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>25</td>\n",
       "      <td>2019-06-11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>26</td>\n",
       "      <td>2019-01-21</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>27</td>\n",
       "      <td>2019-08-05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>28</td>\n",
       "      <td>2019-10-03</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>29</td>\n",
       "      <td>2019-07-09</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>30</td>\n",
       "      <td>2019-03-20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>970</th>\n",
       "      <td>971</td>\n",
       "      <td>2019-03-17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>971</th>\n",
       "      <td>972</td>\n",
       "      <td>2019-07-16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>972</th>\n",
       "      <td>973</td>\n",
       "      <td>2019-06-13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>973</th>\n",
       "      <td>974</td>\n",
       "      <td>2019-09-09</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>974</th>\n",
       "      <td>975</td>\n",
       "      <td>2019-09-19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>975</th>\n",
       "      <td>976</td>\n",
       "      <td>2019-08-27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>976</th>\n",
       "      <td>977</td>\n",
       "      <td>2020-02-10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>977</th>\n",
       "      <td>978</td>\n",
       "      <td>2019-08-21</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>978</th>\n",
       "      <td>979</td>\n",
       "      <td>2019-07-21</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>979</th>\n",
       "      <td>980</td>\n",
       "      <td>2019-05-28</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>980</th>\n",
       "      <td>981</td>\n",
       "      <td>2019-09-03</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>981</th>\n",
       "      <td>982</td>\n",
       "      <td>2019-07-28</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>982</th>\n",
       "      <td>983</td>\n",
       "      <td>2019-12-30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>983</th>\n",
       "      <td>984</td>\n",
       "      <td>2019-02-11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>984</th>\n",
       "      <td>985</td>\n",
       "      <td>2019-07-04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>985</th>\n",
       "      <td>986</td>\n",
       "      <td>2019-07-31</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>986</th>\n",
       "      <td>987</td>\n",
       "      <td>2019-09-11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>987</th>\n",
       "      <td>988</td>\n",
       "      <td>2019-07-04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>988</th>\n",
       "      <td>989</td>\n",
       "      <td>2019-08-30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>989</th>\n",
       "      <td>990</td>\n",
       "      <td>2020-03-22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>990</th>\n",
       "      <td>991</td>\n",
       "      <td>2019-06-15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>991</th>\n",
       "      <td>992</td>\n",
       "      <td>2019-08-22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>992</th>\n",
       "      <td>993</td>\n",
       "      <td>2019-08-17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>993</th>\n",
       "      <td>994</td>\n",
       "      <td>2019-08-14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>994</th>\n",
       "      <td>995</td>\n",
       "      <td>2019-06-13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>995</th>\n",
       "      <td>996</td>\n",
       "      <td>2019-09-12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>996</th>\n",
       "      <td>997</td>\n",
       "      <td>2019-02-07</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>997</th>\n",
       "      <td>998</td>\n",
       "      <td>2019-11-26</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>998</th>\n",
       "      <td>999</td>\n",
       "      <td>2019-08-18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>999</th>\n",
       "      <td>1000</td>\n",
       "      <td>2019-06-15</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1000 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     玩家id       付费时间\n",
       "0       1 2019-11-15\n",
       "1       2 2019-08-13\n",
       "2       3 2019-12-03\n",
       "3       4 2019-11-25\n",
       "4       5 2019-08-11\n",
       "5       6 2019-08-04\n",
       "6       7 2019-03-24\n",
       "7       8 2019-08-07\n",
       "8       9 2019-06-14\n",
       "9      10 2019-01-09\n",
       "10     11 2019-09-26\n",
       "11     12 2019-06-18\n",
       "12     13 2019-11-10\n",
       "13     14 2019-12-28\n",
       "14     15 2019-11-16\n",
       "15     16 2019-09-24\n",
       "16     17 2019-10-19\n",
       "17     18 2019-07-19\n",
       "18     19 2019-08-05\n",
       "19     20 2019-04-12\n",
       "20     21 2019-10-18\n",
       "21     22 2019-08-16\n",
       "22     23 2019-10-02\n",
       "23     24 2019-04-06\n",
       "24     25 2019-06-11\n",
       "25     26 2019-01-21\n",
       "26     27 2019-08-05\n",
       "27     28 2019-10-03\n",
       "28     29 2019-07-09\n",
       "29     30 2019-03-20\n",
       "..    ...        ...\n",
       "970   971 2019-03-17\n",
       "971   972 2019-07-16\n",
       "972   973 2019-06-13\n",
       "973   974 2019-09-09\n",
       "974   975 2019-09-19\n",
       "975   976 2019-08-27\n",
       "976   977 2020-02-10\n",
       "977   978 2019-08-21\n",
       "978   979 2019-07-21\n",
       "979   980 2019-05-28\n",
       "980   981 2019-09-03\n",
       "981   982 2019-07-28\n",
       "982   983 2019-12-30\n",
       "983   984 2019-02-11\n",
       "984   985 2019-07-04\n",
       "985   986 2019-07-31\n",
       "986   987 2019-09-11\n",
       "987   988 2019-07-04\n",
       "988   989 2019-08-30\n",
       "989   990 2020-03-22\n",
       "990   991 2019-06-15\n",
       "991   992 2019-08-22\n",
       "992   993 2019-08-17\n",
       "993   994 2019-08-14\n",
       "994   995 2019-06-13\n",
       "995   996 2019-09-12\n",
       "996   997 2019-02-07\n",
       "997   998 2019-11-26\n",
       "998   999 2019-08-18\n",
       "999  1000 2019-06-15\n",
       "\n",
       "[1000 rows x 2 columns]"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data1.groupby('玩家id',as_index=False)['付费时间'].min()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "data_first_day_pay = data1.groupby('玩家id',as_index=False)['付费时间'].min()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "data_first_day_pay['首天付费']= 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "data2 = pd.merge(left=data1,right=data_first_day_pay,how ='outer')\n",
    "data2.fillna(0,inplace = True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>玩家id</th>\n",
       "      <th>注册时间</th>\n",
       "      <th>付费时间</th>\n",
       "      <th>付费额度</th>\n",
       "      <th>计费点id</th>\n",
       "      <th>首天付费</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>1.99</td>\n",
       "      <td>3</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>9.99</td>\n",
       "      <td>1</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-16</td>\n",
       "      <td>29.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-16</td>\n",
       "      <td>19.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-16</td>\n",
       "      <td>24.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-16</td>\n",
       "      <td>17.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-17</td>\n",
       "      <td>34.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-18</td>\n",
       "      <td>2.99</td>\n",
       "      <td>2</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-18</td>\n",
       "      <td>49.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-19</td>\n",
       "      <td>99.99</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-20</td>\n",
       "      <td>49.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-20</td>\n",
       "      <td>24.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-20</td>\n",
       "      <td>9.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-22</td>\n",
       "      <td>49.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-22</td>\n",
       "      <td>49.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-23</td>\n",
       "      <td>1.99</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-24</td>\n",
       "      <td>29.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-24</td>\n",
       "      <td>14.99</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-24</td>\n",
       "      <td>49.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-24</td>\n",
       "      <td>9.99</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-25</td>\n",
       "      <td>49.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-25</td>\n",
       "      <td>49.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-25</td>\n",
       "      <td>99.99</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-26</td>\n",
       "      <td>14.99</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-26</td>\n",
       "      <td>24.99</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-26</td>\n",
       "      <td>19.99</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-26</td>\n",
       "      <td>99.99</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-27</td>\n",
       "      <td>49.99</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-28</td>\n",
       "      <td>99.99</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-29</td>\n",
       "      <td>99.99</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31916</th>\n",
       "      <td>999</td>\n",
       "      <td>2019-08-06</td>\n",
       "      <td>2019-10-20</td>\n",
       "      <td>4.99</td>\n",
       "      <td>2</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31917</th>\n",
       "      <td>999</td>\n",
       "      <td>2019-08-06</td>\n",
       "      <td>2019-10-22</td>\n",
       "      <td>1.99</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31918</th>\n",
       "      <td>999</td>\n",
       "      <td>2019-08-06</td>\n",
       "      <td>2019-11-12</td>\n",
       "      <td>4.99</td>\n",
       "      <td>2</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31919</th>\n",
       "      <td>999</td>\n",
       "      <td>2019-08-06</td>\n",
       "      <td>2019-11-12</td>\n",
       "      <td>9.99</td>\n",
       "      <td>2</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31920</th>\n",
       "      <td>1000</td>\n",
       "      <td>2019-06-14</td>\n",
       "      <td>2019-06-15</td>\n",
       "      <td>1.99</td>\n",
       "      <td>3</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31921</th>\n",
       "      <td>1000</td>\n",
       "      <td>2019-06-14</td>\n",
       "      <td>2019-06-15</td>\n",
       "      <td>0.99</td>\n",
       "      <td>3</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31922</th>\n",
       "      <td>1000</td>\n",
       "      <td>2019-06-14</td>\n",
       "      <td>2019-06-15</td>\n",
       "      <td>1.99</td>\n",
       "      <td>3</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31923</th>\n",
       "      <td>1000</td>\n",
       "      <td>2019-06-14</td>\n",
       "      <td>2019-06-19</td>\n",
       "      <td>9.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31924</th>\n",
       "      <td>1000</td>\n",
       "      <td>2019-06-14</td>\n",
       "      <td>2019-06-19</td>\n",
       "      <td>7.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31925</th>\n",
       "      <td>1000</td>\n",
       "      <td>2019-06-14</td>\n",
       "      <td>2019-06-19</td>\n",
       "      <td>19.99</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31926</th>\n",
       "      <td>1000</td>\n",
       "      <td>2019-06-14</td>\n",
       "      <td>2019-06-19</td>\n",
       "      <td>4.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31927</th>\n",
       "      <td>1000</td>\n",
       "      <td>2019-06-14</td>\n",
       "      <td>2019-06-19</td>\n",
       "      <td>2.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31928</th>\n",
       "      <td>1000</td>\n",
       "      <td>2019-06-14</td>\n",
       "      <td>2019-06-19</td>\n",
       "      <td>1.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31929</th>\n",
       "      <td>1000</td>\n",
       "      <td>2019-06-14</td>\n",
       "      <td>2019-06-19</td>\n",
       "      <td>9.99</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31930</th>\n",
       "      <td>1000</td>\n",
       "      <td>2019-06-14</td>\n",
       "      <td>2019-06-21</td>\n",
       "      <td>29.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31931</th>\n",
       "      <td>1000</td>\n",
       "      <td>2019-06-14</td>\n",
       "      <td>2019-06-21</td>\n",
       "      <td>9.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31932</th>\n",
       "      <td>1000</td>\n",
       "      <td>2019-06-14</td>\n",
       "      <td>2019-06-21</td>\n",
       "      <td>9.99</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31933</th>\n",
       "      <td>1000</td>\n",
       "      <td>2019-06-14</td>\n",
       "      <td>2019-06-21</td>\n",
       "      <td>99.99</td>\n",
       "      <td>2</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31934</th>\n",
       "      <td>1000</td>\n",
       "      <td>2019-06-14</td>\n",
       "      <td>2019-06-21</td>\n",
       "      <td>4.99</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31935</th>\n",
       "      <td>1000</td>\n",
       "      <td>2019-06-14</td>\n",
       "      <td>2019-06-21</td>\n",
       "      <td>49.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31936</th>\n",
       "      <td>1000</td>\n",
       "      <td>2019-06-14</td>\n",
       "      <td>2019-06-22</td>\n",
       "      <td>9.99</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31937</th>\n",
       "      <td>1000</td>\n",
       "      <td>2019-06-14</td>\n",
       "      <td>2019-07-01</td>\n",
       "      <td>9.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31938</th>\n",
       "      <td>1000</td>\n",
       "      <td>2019-06-14</td>\n",
       "      <td>2019-08-29</td>\n",
       "      <td>9.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31939</th>\n",
       "      <td>1000</td>\n",
       "      <td>2019-06-14</td>\n",
       "      <td>2019-09-13</td>\n",
       "      <td>9.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31940</th>\n",
       "      <td>1000</td>\n",
       "      <td>2019-06-14</td>\n",
       "      <td>2019-09-19</td>\n",
       "      <td>9.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31941</th>\n",
       "      <td>1000</td>\n",
       "      <td>2019-06-14</td>\n",
       "      <td>2019-09-22</td>\n",
       "      <td>9.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31942</th>\n",
       "      <td>1000</td>\n",
       "      <td>2019-06-14</td>\n",
       "      <td>2019-09-24</td>\n",
       "      <td>9.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31943</th>\n",
       "      <td>1000</td>\n",
       "      <td>2019-06-14</td>\n",
       "      <td>2019-09-24</td>\n",
       "      <td>9.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31944</th>\n",
       "      <td>1000</td>\n",
       "      <td>2019-06-14</td>\n",
       "      <td>2019-10-22</td>\n",
       "      <td>9.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31945</th>\n",
       "      <td>1000</td>\n",
       "      <td>2019-06-14</td>\n",
       "      <td>2020-03-21</td>\n",
       "      <td>9.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>31946 rows × 6 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "       玩家id       注册时间       付费时间   付费额度  计费点id  首天付费\n",
       "0         1 2019-11-15 2019-11-15   1.99      3   1.0\n",
       "1         1 2019-11-15 2019-11-15   9.99      1   1.0\n",
       "2         1 2019-11-15 2019-11-16  29.99      3   0.0\n",
       "3         1 2019-11-15 2019-11-16  19.99      3   0.0\n",
       "4         1 2019-11-15 2019-11-16  24.99      3   0.0\n",
       "5         1 2019-11-15 2019-11-16  17.99      3   0.0\n",
       "6         1 2019-11-15 2019-11-17  34.99      3   0.0\n",
       "7         1 2019-11-15 2019-11-18   2.99      2   0.0\n",
       "8         1 2019-11-15 2019-11-18  49.99      3   0.0\n",
       "9         1 2019-11-15 2019-11-19  99.99      1   0.0\n",
       "10        1 2019-11-15 2019-11-20  49.99      3   0.0\n",
       "11        1 2019-11-15 2019-11-20  24.99      3   0.0\n",
       "12        1 2019-11-15 2019-11-20   9.99      3   0.0\n",
       "13        1 2019-11-15 2019-11-22  49.99      3   0.0\n",
       "14        1 2019-11-15 2019-11-22  49.99      3   0.0\n",
       "15        1 2019-11-15 2019-11-23   1.99      1   0.0\n",
       "16        1 2019-11-15 2019-11-24  29.99      3   0.0\n",
       "17        1 2019-11-15 2019-11-24  14.99      1   0.0\n",
       "18        1 2019-11-15 2019-11-24  49.99      3   0.0\n",
       "19        1 2019-11-15 2019-11-24   9.99      1   0.0\n",
       "20        1 2019-11-15 2019-11-25  49.99      3   0.0\n",
       "21        1 2019-11-15 2019-11-25  49.99      3   0.0\n",
       "22        1 2019-11-15 2019-11-25  99.99      1   0.0\n",
       "23        1 2019-11-15 2019-11-26  14.99      1   0.0\n",
       "24        1 2019-11-15 2019-11-26  24.99      1   0.0\n",
       "25        1 2019-11-15 2019-11-26  19.99      1   0.0\n",
       "26        1 2019-11-15 2019-11-26  99.99      1   0.0\n",
       "27        1 2019-11-15 2019-11-27  49.99      1   0.0\n",
       "28        1 2019-11-15 2019-11-28  99.99      1   0.0\n",
       "29        1 2019-11-15 2019-11-29  99.99      1   0.0\n",
       "...     ...        ...        ...    ...    ...   ...\n",
       "31916   999 2019-08-06 2019-10-20   4.99      2   0.0\n",
       "31917   999 2019-08-06 2019-10-22   1.99      1   0.0\n",
       "31918   999 2019-08-06 2019-11-12   4.99      2   0.0\n",
       "31919   999 2019-08-06 2019-11-12   9.99      2   0.0\n",
       "31920  1000 2019-06-14 2019-06-15   1.99      3   1.0\n",
       "31921  1000 2019-06-14 2019-06-15   0.99      3   1.0\n",
       "31922  1000 2019-06-14 2019-06-15   1.99      3   1.0\n",
       "31923  1000 2019-06-14 2019-06-19   9.99      3   0.0\n",
       "31924  1000 2019-06-14 2019-06-19   7.99      3   0.0\n",
       "31925  1000 2019-06-14 2019-06-19  19.99      1   0.0\n",
       "31926  1000 2019-06-14 2019-06-19   4.99      3   0.0\n",
       "31927  1000 2019-06-14 2019-06-19   2.99      3   0.0\n",
       "31928  1000 2019-06-14 2019-06-19   1.99      3   0.0\n",
       "31929  1000 2019-06-14 2019-06-19   9.99      1   0.0\n",
       "31930  1000 2019-06-14 2019-06-21  29.99      3   0.0\n",
       "31931  1000 2019-06-14 2019-06-21   9.99      3   0.0\n",
       "31932  1000 2019-06-14 2019-06-21   9.99      1   0.0\n",
       "31933  1000 2019-06-14 2019-06-21  99.99      2   0.0\n",
       "31934  1000 2019-06-14 2019-06-21   4.99      1   0.0\n",
       "31935  1000 2019-06-14 2019-06-21  49.99      3   0.0\n",
       "31936  1000 2019-06-14 2019-06-22   9.99      1   0.0\n",
       "31937  1000 2019-06-14 2019-07-01   9.99      3   0.0\n",
       "31938  1000 2019-06-14 2019-08-29   9.99      3   0.0\n",
       "31939  1000 2019-06-14 2019-09-13   9.99      3   0.0\n",
       "31940  1000 2019-06-14 2019-09-19   9.99      3   0.0\n",
       "31941  1000 2019-06-14 2019-09-22   9.99      3   0.0\n",
       "31942  1000 2019-06-14 2019-09-24   9.99      3   0.0\n",
       "31943  1000 2019-06-14 2019-09-24   9.99      3   0.0\n",
       "31944  1000 2019-06-14 2019-10-22   9.99      3   0.0\n",
       "31945  1000 2019-06-14 2020-03-21   9.99      3   0.0\n",
       "\n",
       "[31946 rows x 6 columns]"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 首次付费"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([    0,    34,    44,   209,   232,   351,   406,   450,   463,\n",
       "         497,   515,   708,   725,   738,   770,   808,   823,   907,\n",
       "         926,   999,  1029,  1054,  1104,  1122,  1142,  1152,  1169,\n",
       "        1179,  1204,  1215,  1339,  1356,  1385,  1395,  1412,  1447,\n",
       "        1477,  1510,  1521,  1536,  1638,  1650,  1663,  1798,  1824,\n",
       "        1857,  1868,  1882,  1896,  1998,  2016,  2027,  2042,  2153,\n",
       "        2163,  2199,  2211,  2226,  2238,  2331,  2356,  2416,  2441,\n",
       "        2458,  2488,  2507,  2519,  2532,  2551,  2565,  2584,  2594,\n",
       "        2606,  2643,  2653,  2680,  2704,  2715,  2727,  2742,  2755,\n",
       "        2776,  2827,  2838,  2855,  2866,  2878,  2923,  3002,  3037,\n",
       "        3051,  3095,  3106,  3132,  3153,  3400,  3410,  3422,  3557,\n",
       "        3586,  3627,  3667,  3833,  3984,  4111,  4152,  4174,  4236,\n",
       "        4251,  4282,  4298,  4311,  4328,  4365,  4375,  4398,  4409,\n",
       "        4435,  4465,  4475,  4498,  4508,  4544,  4562,  4610,  4685,\n",
       "        4698,  4708,  4723,  4742,  4767,  4785,  4811,  4821,  4841,\n",
       "        4852,  4877,  4887,  4912,  4922,  4933,  4954,  4984,  5028,\n",
       "        5054,  5084,  5098,  5108,  5120,  5133,  5183,  5195,  5207,\n",
       "        5222,  5237,  5283,  5295,  5306,  5320,  5653,  5668,  5817,\n",
       "        5863,  5875,  5987,  6003,  6017,  6033,  6053,  6068,  6087,\n",
       "        6228,  6254,  6266,  6277,  6291,  6308,  6330,  6342,  6370,\n",
       "        6382,  6394,  6428,  6454,  6509,  6524,  6534,  6547,  6561,\n",
       "        6571,  6585,  6634,  6653,  6663,  6676,  6697,  6707,  6717,\n",
       "        6731,  6743,  6756,  6777,  6796,  6806,  6817,  6828,  6841,\n",
       "        6854,  6885,  6946,  6962,  7492,  7506,  7526,  7556,  7576,\n",
       "        7643,  7655,  7687,  7719,  7765,  7892,  8007,  8023,  8038,\n",
       "        8052,  8062,  8076,  8093,  8114,  8136,  8174,  8240,  8598,\n",
       "        8638,  8657,  8671,  8692,  8715,  8739,  8769,  8791,  8802,\n",
       "        8817,  8862,  8891,  8927,  8957,  8967,  8977,  9017,  9043,\n",
       "        9074,  9085,  9099,  9122,  9156,  9172,  9183,  9195,  9260,\n",
       "        9279,  9289,  9337,  9355,  9397,  9413,  9524,  9563,  9581,\n",
       "        9599,  9610,  9630,  9642,  9772,  9783,  9803,  9819,  9900,\n",
       "        9935,  9947,  9989, 10006, 10018, 10069, 10116, 10154, 10182,\n",
       "       10218, 10231, 10274, 10291, 10324, 10337, 10349, 10375, 10388,\n",
       "       10413, 10423, 10511, 10533, 10550, 10561, 10575, 10595, 10622,\n",
       "       10638, 10654, 10696, 10719, 10729, 10766, 10794, 10820, 10831,\n",
       "       10849, 10892, 10931, 10941, 10965, 10979, 10997, 11008, 11035,\n",
       "       11045, 11103, 11128, 11165, 11189, 11255, 11323, 11415, 11431,\n",
       "       11462, 11510, 11633, 11645, 11666, 11679, 11690, 11703, 11852,\n",
       "       11866, 11883, 11912, 11922, 11954, 11982, 11992, 12009, 12020,\n",
       "       12030, 12046, 12077, 12087, 12103, 12116, 12130, 12145, 12157,\n",
       "       12184, 12228, 12299, 12314, 12340, 12352, 12392, 12409, 12419,\n",
       "       12562, 12579, 12589, 12604, 12615, 12636, 12659, 12672, 12685,\n",
       "       12709, 12723, 12733, 12750, 12772, 12795, 12863, 12887, 12906,\n",
       "       12924, 13086, 13098, 13111, 13126, 13149, 13182, 13200, 13249,\n",
       "       13264, 13274, 13306, 13347, 13357, 13378, 13523, 13537, 13572,\n",
       "       13601, 13626, 13643, 13656, 13673, 13705, 13715, 13732, 13750,\n",
       "       13772, 13785, 13797, 13835, 13846, 13858, 14128, 14157, 14356,\n",
       "       14378, 14397, 14407, 14422, 14445, 14457, 14471, 14486, 14521,\n",
       "       14542, 14556, 14571, 14589, 14618, 14633, 14647, 14665, 14681,\n",
       "       14695, 14736, 14749, 14769, 14799, 14811, 14885, 14910, 14924,\n",
       "       14940, 14959, 14979, 15010, 15025, 15036, 15159, 15193, 15211,\n",
       "       15233, 15243, 15285, 15297, 15325, 15346, 15356, 15373, 15394,\n",
       "       15417, 15428, 15445, 15501, 15543, 15575, 15600, 15614, 15624,\n",
       "       15634, 15644, 15659, 15669, 15679, 15708, 15735, 15758, 15773,\n",
       "       15811, 15822, 15835, 15847, 15889, 15902, 15924, 15934, 15956,\n",
       "       15968, 15996, 16009, 16154, 16165, 16197, 16211, 16232, 16264,\n",
       "       16281, 16301, 16315, 16327, 16348, 16361, 16378, 16398, 16410,\n",
       "       16430, 16458, 16502, 16519, 16534, 16552, 16566, 16617, 16632,\n",
       "       16651, 16671, 16688, 16709, 16750, 16762, 16791, 16805, 16816,\n",
       "       16827, 16891, 16906, 16917, 17105, 17125, 17153, 17163, 17184,\n",
       "       17194, 17204, 17233, 17247, 17276, 17296, 17308, 17322, 17350,\n",
       "       17504, 17516, 17528, 17609, 17629, 17644, 17711, 17773, 17789,\n",
       "       17810, 17823, 17841, 17869, 18011, 18111, 18124, 18147, 18160,\n",
       "       18171, 18184, 18195, 18205, 18255, 18314, 18359, 18384, 18402,\n",
       "       18420, 18441, 18453, 18469, 18497, 18548, 18609, 18641, 18666,\n",
       "       18700, 18720, 18756, 18797, 18869, 18907, 18917, 18929, 18955,\n",
       "       18995, 19011, 19049, 19072, 19090, 19101, 19171, 19707, 19754,\n",
       "       19768, 19785, 19803, 19815, 19825, 19837, 19847, 19863, 19879,\n",
       "       19892, 19904, 19915, 19927, 20017, 20029, 20062, 20109, 20135,\n",
       "       20176, 20240, 20322, 20332, 20346, 20358, 20368, 20398, 20411,\n",
       "       20439, 20450, 20463, 20480, 20496, 20512, 20643, 20659, 20669,\n",
       "       20681, 20691, 20707, 20748, 20779, 20802, 20825, 20844, 20857,\n",
       "       20868, 20879, 20898, 20908, 20924, 20952, 21141, 21164, 21190,\n",
       "       21205, 21217, 21237, 21248, 21259, 21277, 21316, 21339, 21355,\n",
       "       21368, 21393, 21416, 21439, 21455, 21475, 21507, 21543, 21556,\n",
       "       21571, 21625, 21647, 21685, 21758, 21794, 21805, 21819, 21839,\n",
       "       21860, 21889, 21904, 21978, 22039, 22058, 22072, 22111, 22124,\n",
       "       22166, 22185, 22209, 22230, 22279, 22298, 22308, 22336, 22372,\n",
       "       22384, 22415, 22498, 22517, 22558, 22568, 22589, 22627, 22663,\n",
       "       22676, 22687, 22698, 22715, 22735, 22746, 22758, 22771, 22831,\n",
       "       22965, 22990, 23003, 23013, 23029, 23076, 23087, 23106, 23131,\n",
       "       23143, 23175, 23192, 23479, 23518, 23573, 23586, 23676, 23693,\n",
       "       23705, 23723, 23738, 23750, 23778, 23802, 23865, 23876, 23890,\n",
       "       23916, 23946, 23986, 23997, 24008, 24026, 24036, 24061, 24085,\n",
       "       24102, 24118, 24129, 24166, 24183, 24204, 24217, 24244, 24259,\n",
       "       24273, 24285, 24313, 24358, 24387, 24454, 24467, 24483, 24493,\n",
       "       24517, 24556, 24592, 24627, 24657, 24676, 24689, 24755, 24799,\n",
       "       24810, 24826, 24841, 24869, 24892, 24963, 24977, 24993, 25029,\n",
       "       25043, 25054, 25123, 25145, 25158, 25172, 25197, 25219, 25229,\n",
       "       25247, 25303, 25333, 25359, 25369, 25383, 25450, 25497, 25536,\n",
       "       25548, 25561, 25571, 25586, 25599, 25622, 25645, 25663, 25725,\n",
       "       25781, 25796, 25806, 25825, 25845, 25886, 25905, 25916, 26008,\n",
       "       26021, 26037, 26047, 26116, 26128, 26140, 26157, 26168, 26183,\n",
       "       26207, 26253, 26273, 26296, 26334, 26464, 26493, 26548, 26576,\n",
       "       26589, 26604, 26616, 26647, 26741, 26784, 26808, 26827, 27020,\n",
       "       27048, 27061, 27110, 27133, 27145, 27162, 27199, 27209, 27219,\n",
       "       27254, 27269, 27314, 27324, 27341, 27359, 27374, 27384, 27414,\n",
       "       27424, 27465, 27479, 27512, 27533, 27546, 27568, 27585, 27646,\n",
       "       27666, 27797, 27833, 27858, 27875, 27885, 28045, 28059, 28069,\n",
       "       28080, 28116, 28131, 28158, 28168, 28179, 28200, 28212, 28240,\n",
       "       28256, 28268, 28278, 28300, 28315, 28342, 28353, 28368, 28380,\n",
       "       28398, 28413, 28435, 28505, 28566, 28579, 28639, 28651, 28691,\n",
       "       28703, 28719, 28735, 28763, 28773, 28792, 28814, 28824, 28835,\n",
       "       28848, 28864, 28892, 28916, 28948, 28965, 29055, 29065, 29076,\n",
       "       29124, 29138, 29246, 29269, 29299, 29987, 30029, 30269, 30290,\n",
       "       30301, 30319, 30338, 30355, 30371, 30382, 30416, 30432, 30450,\n",
       "       30480, 30514, 30526, 30731, 30749, 30796, 30806, 30817, 30863,\n",
       "       30874, 30888, 30911, 30964, 31155, 31176, 31189, 31236, 31248,\n",
       "       31259, 31276, 31286, 31326, 31338, 31359, 31390, 31429, 31442,\n",
       "       31471, 31494, 31508, 31572, 31635, 31648, 31666, 31681, 31705,\n",
       "       31719, 31756, 31767, 31794, 31814, 31824, 31834, 31897, 31910,\n",
       "       31920], dtype=int64)"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data2[data2['首天付费']==1].reset_index().groupby('玩家id')['index'].min().values\n",
    "#找到首次付费的index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "firt_pay_index = data2[data2['首天付费']==1].reset_index().groupby('玩家id')['index'].min().values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "data2['首次付费']=0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "data2.loc[firt_pay_index,'首次付费']=1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>玩家id</th>\n",
       "      <th>注册时间</th>\n",
       "      <th>付费时间</th>\n",
       "      <th>付费额度</th>\n",
       "      <th>计费点id</th>\n",
       "      <th>首天付费</th>\n",
       "      <th>首次付费</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>1.99</td>\n",
       "      <td>3</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>9.99</td>\n",
       "      <td>1</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-16</td>\n",
       "      <td>29.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-16</td>\n",
       "      <td>19.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-16</td>\n",
       "      <td>24.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-16</td>\n",
       "      <td>17.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-17</td>\n",
       "      <td>34.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-18</td>\n",
       "      <td>2.99</td>\n",
       "      <td>2</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-18</td>\n",
       "      <td>49.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-19</td>\n",
       "      <td>99.99</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-20</td>\n",
       "      <td>49.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-20</td>\n",
       "      <td>24.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-20</td>\n",
       "      <td>9.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-22</td>\n",
       "      <td>49.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-22</td>\n",
       "      <td>49.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-23</td>\n",
       "      <td>1.99</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-24</td>\n",
       "      <td>29.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-24</td>\n",
       "      <td>14.99</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-24</td>\n",
       "      <td>49.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-24</td>\n",
       "      <td>9.99</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-25</td>\n",
       "      <td>49.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-25</td>\n",
       "      <td>49.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-25</td>\n",
       "      <td>99.99</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-26</td>\n",
       "      <td>14.99</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-26</td>\n",
       "      <td>24.99</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-26</td>\n",
       "      <td>19.99</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-26</td>\n",
       "      <td>99.99</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-27</td>\n",
       "      <td>49.99</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-28</td>\n",
       "      <td>99.99</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-29</td>\n",
       "      <td>99.99</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31916</th>\n",
       "      <td>999</td>\n",
       "      <td>2019-08-06</td>\n",
       "      <td>2019-10-20</td>\n",
       "      <td>4.99</td>\n",
       "      <td>2</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31917</th>\n",
       "      <td>999</td>\n",
       "      <td>2019-08-06</td>\n",
       "      <td>2019-10-22</td>\n",
       "      <td>1.99</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31918</th>\n",
       "      <td>999</td>\n",
       "      <td>2019-08-06</td>\n",
       "      <td>2019-11-12</td>\n",
       "      <td>4.99</td>\n",
       "      <td>2</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31919</th>\n",
       "      <td>999</td>\n",
       "      <td>2019-08-06</td>\n",
       "      <td>2019-11-12</td>\n",
       "      <td>9.99</td>\n",
       "      <td>2</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31920</th>\n",
       "      <td>1000</td>\n",
       "      <td>2019-06-14</td>\n",
       "      <td>2019-06-15</td>\n",
       "      <td>1.99</td>\n",
       "      <td>3</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31921</th>\n",
       "      <td>1000</td>\n",
       "      <td>2019-06-14</td>\n",
       "      <td>2019-06-15</td>\n",
       "      <td>0.99</td>\n",
       "      <td>3</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31922</th>\n",
       "      <td>1000</td>\n",
       "      <td>2019-06-14</td>\n",
       "      <td>2019-06-15</td>\n",
       "      <td>1.99</td>\n",
       "      <td>3</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31923</th>\n",
       "      <td>1000</td>\n",
       "      <td>2019-06-14</td>\n",
       "      <td>2019-06-19</td>\n",
       "      <td>9.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31924</th>\n",
       "      <td>1000</td>\n",
       "      <td>2019-06-14</td>\n",
       "      <td>2019-06-19</td>\n",
       "      <td>7.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31925</th>\n",
       "      <td>1000</td>\n",
       "      <td>2019-06-14</td>\n",
       "      <td>2019-06-19</td>\n",
       "      <td>19.99</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31926</th>\n",
       "      <td>1000</td>\n",
       "      <td>2019-06-14</td>\n",
       "      <td>2019-06-19</td>\n",
       "      <td>4.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31927</th>\n",
       "      <td>1000</td>\n",
       "      <td>2019-06-14</td>\n",
       "      <td>2019-06-19</td>\n",
       "      <td>2.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31928</th>\n",
       "      <td>1000</td>\n",
       "      <td>2019-06-14</td>\n",
       "      <td>2019-06-19</td>\n",
       "      <td>1.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31929</th>\n",
       "      <td>1000</td>\n",
       "      <td>2019-06-14</td>\n",
       "      <td>2019-06-19</td>\n",
       "      <td>9.99</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31930</th>\n",
       "      <td>1000</td>\n",
       "      <td>2019-06-14</td>\n",
       "      <td>2019-06-21</td>\n",
       "      <td>29.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31931</th>\n",
       "      <td>1000</td>\n",
       "      <td>2019-06-14</td>\n",
       "      <td>2019-06-21</td>\n",
       "      <td>9.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31932</th>\n",
       "      <td>1000</td>\n",
       "      <td>2019-06-14</td>\n",
       "      <td>2019-06-21</td>\n",
       "      <td>9.99</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31933</th>\n",
       "      <td>1000</td>\n",
       "      <td>2019-06-14</td>\n",
       "      <td>2019-06-21</td>\n",
       "      <td>99.99</td>\n",
       "      <td>2</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31934</th>\n",
       "      <td>1000</td>\n",
       "      <td>2019-06-14</td>\n",
       "      <td>2019-06-21</td>\n",
       "      <td>4.99</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31935</th>\n",
       "      <td>1000</td>\n",
       "      <td>2019-06-14</td>\n",
       "      <td>2019-06-21</td>\n",
       "      <td>49.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31936</th>\n",
       "      <td>1000</td>\n",
       "      <td>2019-06-14</td>\n",
       "      <td>2019-06-22</td>\n",
       "      <td>9.99</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31937</th>\n",
       "      <td>1000</td>\n",
       "      <td>2019-06-14</td>\n",
       "      <td>2019-07-01</td>\n",
       "      <td>9.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31938</th>\n",
       "      <td>1000</td>\n",
       "      <td>2019-06-14</td>\n",
       "      <td>2019-08-29</td>\n",
       "      <td>9.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31939</th>\n",
       "      <td>1000</td>\n",
       "      <td>2019-06-14</td>\n",
       "      <td>2019-09-13</td>\n",
       "      <td>9.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31940</th>\n",
       "      <td>1000</td>\n",
       "      <td>2019-06-14</td>\n",
       "      <td>2019-09-19</td>\n",
       "      <td>9.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31941</th>\n",
       "      <td>1000</td>\n",
       "      <td>2019-06-14</td>\n",
       "      <td>2019-09-22</td>\n",
       "      <td>9.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31942</th>\n",
       "      <td>1000</td>\n",
       "      <td>2019-06-14</td>\n",
       "      <td>2019-09-24</td>\n",
       "      <td>9.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31943</th>\n",
       "      <td>1000</td>\n",
       "      <td>2019-06-14</td>\n",
       "      <td>2019-09-24</td>\n",
       "      <td>9.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31944</th>\n",
       "      <td>1000</td>\n",
       "      <td>2019-06-14</td>\n",
       "      <td>2019-10-22</td>\n",
       "      <td>9.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31945</th>\n",
       "      <td>1000</td>\n",
       "      <td>2019-06-14</td>\n",
       "      <td>2020-03-21</td>\n",
       "      <td>9.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>31946 rows × 7 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "       玩家id       注册时间       付费时间   付费额度  计费点id  首天付费  首次付费\n",
       "0         1 2019-11-15 2019-11-15   1.99      3   1.0     1\n",
       "1         1 2019-11-15 2019-11-15   9.99      1   1.0     0\n",
       "2         1 2019-11-15 2019-11-16  29.99      3   0.0     0\n",
       "3         1 2019-11-15 2019-11-16  19.99      3   0.0     0\n",
       "4         1 2019-11-15 2019-11-16  24.99      3   0.0     0\n",
       "5         1 2019-11-15 2019-11-16  17.99      3   0.0     0\n",
       "6         1 2019-11-15 2019-11-17  34.99      3   0.0     0\n",
       "7         1 2019-11-15 2019-11-18   2.99      2   0.0     0\n",
       "8         1 2019-11-15 2019-11-18  49.99      3   0.0     0\n",
       "9         1 2019-11-15 2019-11-19  99.99      1   0.0     0\n",
       "10        1 2019-11-15 2019-11-20  49.99      3   0.0     0\n",
       "11        1 2019-11-15 2019-11-20  24.99      3   0.0     0\n",
       "12        1 2019-11-15 2019-11-20   9.99      3   0.0     0\n",
       "13        1 2019-11-15 2019-11-22  49.99      3   0.0     0\n",
       "14        1 2019-11-15 2019-11-22  49.99      3   0.0     0\n",
       "15        1 2019-11-15 2019-11-23   1.99      1   0.0     0\n",
       "16        1 2019-11-15 2019-11-24  29.99      3   0.0     0\n",
       "17        1 2019-11-15 2019-11-24  14.99      1   0.0     0\n",
       "18        1 2019-11-15 2019-11-24  49.99      3   0.0     0\n",
       "19        1 2019-11-15 2019-11-24   9.99      1   0.0     0\n",
       "20        1 2019-11-15 2019-11-25  49.99      3   0.0     0\n",
       "21        1 2019-11-15 2019-11-25  49.99      3   0.0     0\n",
       "22        1 2019-11-15 2019-11-25  99.99      1   0.0     0\n",
       "23        1 2019-11-15 2019-11-26  14.99      1   0.0     0\n",
       "24        1 2019-11-15 2019-11-26  24.99      1   0.0     0\n",
       "25        1 2019-11-15 2019-11-26  19.99      1   0.0     0\n",
       "26        1 2019-11-15 2019-11-26  99.99      1   0.0     0\n",
       "27        1 2019-11-15 2019-11-27  49.99      1   0.0     0\n",
       "28        1 2019-11-15 2019-11-28  99.99      1   0.0     0\n",
       "29        1 2019-11-15 2019-11-29  99.99      1   0.0     0\n",
       "...     ...        ...        ...    ...    ...   ...   ...\n",
       "31916   999 2019-08-06 2019-10-20   4.99      2   0.0     0\n",
       "31917   999 2019-08-06 2019-10-22   1.99      1   0.0     0\n",
       "31918   999 2019-08-06 2019-11-12   4.99      2   0.0     0\n",
       "31919   999 2019-08-06 2019-11-12   9.99      2   0.0     0\n",
       "31920  1000 2019-06-14 2019-06-15   1.99      3   1.0     1\n",
       "31921  1000 2019-06-14 2019-06-15   0.99      3   1.0     0\n",
       "31922  1000 2019-06-14 2019-06-15   1.99      3   1.0     0\n",
       "31923  1000 2019-06-14 2019-06-19   9.99      3   0.0     0\n",
       "31924  1000 2019-06-14 2019-06-19   7.99      3   0.0     0\n",
       "31925  1000 2019-06-14 2019-06-19  19.99      1   0.0     0\n",
       "31926  1000 2019-06-14 2019-06-19   4.99      3   0.0     0\n",
       "31927  1000 2019-06-14 2019-06-19   2.99      3   0.0     0\n",
       "31928  1000 2019-06-14 2019-06-19   1.99      3   0.0     0\n",
       "31929  1000 2019-06-14 2019-06-19   9.99      1   0.0     0\n",
       "31930  1000 2019-06-14 2019-06-21  29.99      3   0.0     0\n",
       "31931  1000 2019-06-14 2019-06-21   9.99      3   0.0     0\n",
       "31932  1000 2019-06-14 2019-06-21   9.99      1   0.0     0\n",
       "31933  1000 2019-06-14 2019-06-21  99.99      2   0.0     0\n",
       "31934  1000 2019-06-14 2019-06-21   4.99      1   0.0     0\n",
       "31935  1000 2019-06-14 2019-06-21  49.99      3   0.0     0\n",
       "31936  1000 2019-06-14 2019-06-22   9.99      1   0.0     0\n",
       "31937  1000 2019-06-14 2019-07-01   9.99      3   0.0     0\n",
       "31938  1000 2019-06-14 2019-08-29   9.99      3   0.0     0\n",
       "31939  1000 2019-06-14 2019-09-13   9.99      3   0.0     0\n",
       "31940  1000 2019-06-14 2019-09-19   9.99      3   0.0     0\n",
       "31941  1000 2019-06-14 2019-09-22   9.99      3   0.0     0\n",
       "31942  1000 2019-06-14 2019-09-24   9.99      3   0.0     0\n",
       "31943  1000 2019-06-14 2019-09-24   9.99      3   0.0     0\n",
       "31944  1000 2019-06-14 2019-10-22   9.99      3   0.0     0\n",
       "31945  1000 2019-06-14 2020-03-21   9.99      3   0.0     0\n",
       "\n",
       "[31946 rows x 7 columns]"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 已经游玩的天数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [],
   "source": [
    "data2['游玩天数']=(data2['付费时间']-data2['注册时间']).dt.days"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>玩家id</th>\n",
       "      <th>注册时间</th>\n",
       "      <th>付费时间</th>\n",
       "      <th>付费额度</th>\n",
       "      <th>计费点id</th>\n",
       "      <th>首天付费</th>\n",
       "      <th>首次付费</th>\n",
       "      <th>游玩天数</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>1.99</td>\n",
       "      <td>3</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>9.99</td>\n",
       "      <td>1</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-16</td>\n",
       "      <td>29.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-16</td>\n",
       "      <td>19.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-16</td>\n",
       "      <td>24.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   玩家id       注册时间       付费时间   付费额度  计费点id  首天付费  首次付费  游玩天数\n",
       "0     1 2019-11-15 2019-11-15   1.99      3   1.0     1     0\n",
       "1     1 2019-11-15 2019-11-15   9.99      1   1.0     0     0\n",
       "2     1 2019-11-15 2019-11-16  29.99      3   0.0     0     1\n",
       "3     1 2019-11-15 2019-11-16  19.99      3   0.0     0     1\n",
       "4     1 2019-11-15 2019-11-16  24.99      3   0.0     0     1"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data2.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 构造“When”维度"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 月份"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "data2['月份']=data2['付费时间'].dt.month"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 星期"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [],
   "source": [
    "data2['星期']=data2['付费时间'].dt.weekday\n",
    "#0：星期一 \n",
    "#1：星期二"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 是否是周末"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [],
   "source": [
    "data2['是否是周末']=data2['星期'].apply(lambda x:0 if x<=3 else 1 )\n",
    "#星期五-星期日：4-6"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>玩家id</th>\n",
       "      <th>注册时间</th>\n",
       "      <th>付费时间</th>\n",
       "      <th>付费额度</th>\n",
       "      <th>计费点id</th>\n",
       "      <th>首天付费</th>\n",
       "      <th>首次付费</th>\n",
       "      <th>游玩天数</th>\n",
       "      <th>月份</th>\n",
       "      <th>星期</th>\n",
       "      <th>是否是周末</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>1.99</td>\n",
       "      <td>3</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>11</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>9.99</td>\n",
       "      <td>1</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>11</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-16</td>\n",
       "      <td>29.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>11</td>\n",
       "      <td>5</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-16</td>\n",
       "      <td>19.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>11</td>\n",
       "      <td>5</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-16</td>\n",
       "      <td>24.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>11</td>\n",
       "      <td>5</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   玩家id       注册时间       付费时间   付费额度  计费点id  首天付费  首次付费  游玩天数  月份  星期  是否是周末\n",
       "0     1 2019-11-15 2019-11-15   1.99      3   1.0     1     0  11   4      1\n",
       "1     1 2019-11-15 2019-11-15   9.99      1   1.0     0     0  11   4      1\n",
       "2     1 2019-11-15 2019-11-16  29.99      3   0.0     0     1  11   5      1\n",
       "3     1 2019-11-15 2019-11-16  19.99      3   0.0     0     1  11   5      1\n",
       "4     1 2019-11-15 2019-11-16  24.99      3   0.0     0     1  11   5      1"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data2.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 距上次的付费的天数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [],
   "source": [
    "data3 = data2.copy()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [],
   "source": [
    "data3['上次付费时间']=data3.groupby('玩家id')['付费时间'].shift(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [],
   "source": [
    "data3['距上次付费的天数']=(data3['付费时间']-data3['上次付费时间']).dt.days"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>玩家id</th>\n",
       "      <th>注册时间</th>\n",
       "      <th>付费时间</th>\n",
       "      <th>付费额度</th>\n",
       "      <th>计费点id</th>\n",
       "      <th>首天付费</th>\n",
       "      <th>首次付费</th>\n",
       "      <th>游玩天数</th>\n",
       "      <th>月份</th>\n",
       "      <th>星期</th>\n",
       "      <th>是否是周末</th>\n",
       "      <th>上次付费时间</th>\n",
       "      <th>距上次付费的天数</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>1.99</td>\n",
       "      <td>3</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>11</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>NaT</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>9.99</td>\n",
       "      <td>1</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>11</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-16</td>\n",
       "      <td>29.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>11</td>\n",
       "      <td>5</td>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-16</td>\n",
       "      <td>19.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>11</td>\n",
       "      <td>5</td>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-16</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-16</td>\n",
       "      <td>24.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>11</td>\n",
       "      <td>5</td>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-16</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   玩家id       注册时间       付费时间   付费额度  计费点id  首天付费  首次付费  游玩天数  月份  星期  是否是周末  \\\n",
       "0     1 2019-11-15 2019-11-15   1.99      3   1.0     1     0  11   4      1   \n",
       "1     1 2019-11-15 2019-11-15   9.99      1   1.0     0     0  11   4      1   \n",
       "2     1 2019-11-15 2019-11-16  29.99      3   0.0     0     1  11   5      1   \n",
       "3     1 2019-11-15 2019-11-16  19.99      3   0.0     0     1  11   5      1   \n",
       "4     1 2019-11-15 2019-11-16  24.99      3   0.0     0     1  11   5      1   \n",
       "\n",
       "      上次付费时间  距上次付费的天数  \n",
       "0        NaT       NaN  \n",
       "1 2019-11-15       0.0  \n",
       "2 2019-11-15       1.0  \n",
       "3 2019-11-16       0.0  \n",
       "4 2019-11-16       0.0  "
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data3.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>玩家id</th>\n",
       "      <th>注册时间</th>\n",
       "      <th>付费时间</th>\n",
       "      <th>付费额度</th>\n",
       "      <th>计费点id</th>\n",
       "      <th>首天付费</th>\n",
       "      <th>首次付费</th>\n",
       "      <th>游玩天数</th>\n",
       "      <th>月份</th>\n",
       "      <th>星期</th>\n",
       "      <th>是否是周末</th>\n",
       "      <th>上次付费时间</th>\n",
       "      <th>距上次付费的天数</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>1.99</td>\n",
       "      <td>3</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>11</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>9.99</td>\n",
       "      <td>1</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>11</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15 00:00:00</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-16</td>\n",
       "      <td>29.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>11</td>\n",
       "      <td>5</td>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15 00:00:00</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-16</td>\n",
       "      <td>19.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>11</td>\n",
       "      <td>5</td>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-16 00:00:00</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-16</td>\n",
       "      <td>24.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>11</td>\n",
       "      <td>5</td>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-16 00:00:00</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   玩家id       注册时间       付费时间   付费额度  计费点id  首天付费  首次付费  游玩天数  月份  星期  是否是周末  \\\n",
       "0     1 2019-11-15 2019-11-15   1.99      3   1.0     1     0  11   4      1   \n",
       "1     1 2019-11-15 2019-11-15   9.99      1   1.0     0     0  11   4      1   \n",
       "2     1 2019-11-15 2019-11-16  29.99      3   0.0     0     1  11   5      1   \n",
       "3     1 2019-11-15 2019-11-16  19.99      3   0.0     0     1  11   5      1   \n",
       "4     1 2019-11-15 2019-11-16  24.99      3   0.0     0     1  11   5      1   \n",
       "\n",
       "                上次付费时间  距上次付费的天数  \n",
       "0                    0       0.0  \n",
       "1  2019-11-15 00:00:00       0.0  \n",
       "2  2019-11-15 00:00:00       1.0  \n",
       "3  2019-11-16 00:00:00       0.0  \n",
       "4  2019-11-16 00:00:00       0.0  "
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data3.fillna(0,inplace=True)\n",
    "data3.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>玩家id</th>\n",
       "      <th>注册时间</th>\n",
       "      <th>付费时间</th>\n",
       "      <th>付费额度</th>\n",
       "      <th>计费点id</th>\n",
       "      <th>首天付费</th>\n",
       "      <th>首次付费</th>\n",
       "      <th>游玩天数</th>\n",
       "      <th>月份</th>\n",
       "      <th>星期</th>\n",
       "      <th>是否是周末</th>\n",
       "      <th>距上次付费的天数</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>1.99</td>\n",
       "      <td>3</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>11</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>9.99</td>\n",
       "      <td>1</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>11</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-16</td>\n",
       "      <td>29.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>11</td>\n",
       "      <td>5</td>\n",
       "      <td>1</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-16</td>\n",
       "      <td>19.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>11</td>\n",
       "      <td>5</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-16</td>\n",
       "      <td>24.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>11</td>\n",
       "      <td>5</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   玩家id       注册时间       付费时间   付费额度  计费点id  首天付费  首次付费  游玩天数  月份  星期  是否是周末  \\\n",
       "0     1 2019-11-15 2019-11-15   1.99      3   1.0     1     0  11   4      1   \n",
       "1     1 2019-11-15 2019-11-15   9.99      1   1.0     0     0  11   4      1   \n",
       "2     1 2019-11-15 2019-11-16  29.99      3   0.0     0     1  11   5      1   \n",
       "3     1 2019-11-15 2019-11-16  19.99      3   0.0     0     1  11   5      1   \n",
       "4     1 2019-11-15 2019-11-16  24.99      3   0.0     0     1  11   5      1   \n",
       "\n",
       "   距上次付费的天数  \n",
       "0       0.0  \n",
       "1       0.0  \n",
       "2       1.0  \n",
       "3       0.0  \n",
       "4       0.0  "
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data3.drop(labels='上次付费时间',axis=1,inplace=True)\n",
    "data3.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 构造“Who”维度"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 累计消费额"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [],
   "source": [
    "data3['累计消费额']=data3.groupby('玩家id')['付费额度'].cumsum()-data3['付费额度']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 累计订单数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [],
   "source": [
    "data3['累计订单数']=data3.groupby('玩家id')['付费额度'].cumcount()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 均单价"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [],
   "source": [
    "data3['均单价']=(data3['累计消费额']/data3['累计订单数']).fillna(0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>玩家id</th>\n",
       "      <th>注册时间</th>\n",
       "      <th>付费时间</th>\n",
       "      <th>付费额度</th>\n",
       "      <th>计费点id</th>\n",
       "      <th>首天付费</th>\n",
       "      <th>首次付费</th>\n",
       "      <th>游玩天数</th>\n",
       "      <th>月份</th>\n",
       "      <th>星期</th>\n",
       "      <th>是否是周末</th>\n",
       "      <th>距上次付费的天数</th>\n",
       "      <th>累计消费额</th>\n",
       "      <th>累计订单数</th>\n",
       "      <th>均单价</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>1.99</td>\n",
       "      <td>3</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>11</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0</td>\n",
       "      <td>0.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>9.99</td>\n",
       "      <td>1</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>11</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.99</td>\n",
       "      <td>1</td>\n",
       "      <td>1.99</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-16</td>\n",
       "      <td>29.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>11</td>\n",
       "      <td>5</td>\n",
       "      <td>1</td>\n",
       "      <td>1.0</td>\n",
       "      <td>11.98</td>\n",
       "      <td>2</td>\n",
       "      <td>5.99</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-16</td>\n",
       "      <td>19.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>11</td>\n",
       "      <td>5</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>41.97</td>\n",
       "      <td>3</td>\n",
       "      <td>13.99</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1</td>\n",
       "      <td>2019-11-15</td>\n",
       "      <td>2019-11-16</td>\n",
       "      <td>24.99</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>11</td>\n",
       "      <td>5</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>61.96</td>\n",
       "      <td>4</td>\n",
       "      <td>15.49</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   玩家id       注册时间       付费时间   付费额度  计费点id  首天付费  首次付费  游玩天数  月份  星期  是否是周末  \\\n",
       "0     1 2019-11-15 2019-11-15   1.99      3   1.0     1     0  11   4      1   \n",
       "1     1 2019-11-15 2019-11-15   9.99      1   1.0     0     0  11   4      1   \n",
       "2     1 2019-11-15 2019-11-16  29.99      3   0.0     0     1  11   5      1   \n",
       "3     1 2019-11-15 2019-11-16  19.99      3   0.0     0     1  11   5      1   \n",
       "4     1 2019-11-15 2019-11-16  24.99      3   0.0     0     1  11   5      1   \n",
       "\n",
       "   距上次付费的天数  累计消费额  累计订单数    均单价  \n",
       "0       0.0   0.00      0   0.00  \n",
       "1       0.0   1.99      1   1.99  \n",
       "2       1.0  11.98      2   5.99  \n",
       "3       0.0  41.97      3  13.99  \n",
       "4       0.0  61.96      4  15.49  "
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data3.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 构造“Where”维度"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 上次的计费点"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [],
   "source": [
    "data3['上次的计费点'] = data3['计费点id'].shift(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [],
   "source": [
    "data3.loc[data3['首次付费']==1,'上次的计费点']= 0"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 最高频计费点(4个）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "# import seaborn as sns\n",
    "# sns.heatmap(data3.corr())\n",
    "# plt.rcParams['font.sans-serif']=['SimHei'] # 用来正常显示中文标签\n",
    "# plt.rcParams['axes.unicode_minus']=False # 用来正常显示负号"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "2\n",
      "3\n",
      "4\n",
      "5\n",
      "6\n",
      "7\n",
      "8\n",
      "9\n",
      "10\n",
      "11\n",
      "12\n",
      "13\n",
      "14\n",
      "15\n",
      "16\n",
      "17\n",
      "18\n",
      "19\n",
      "20\n",
      "21\n",
      "22\n",
      "23\n",
      "24\n",
      "25\n",
      "26\n",
      "27\n",
      "28\n",
      "29\n",
      "30\n",
      "31\n",
      "32\n",
      "33\n",
      "34\n",
      "35\n",
      "36\n",
      "37\n",
      "38\n",
      "39\n",
      "40\n",
      "41\n",
      "42\n",
      "43\n",
      "44\n",
      "45\n",
      "46\n",
      "47\n",
      "48\n"
     ]
    }
   ],
   "source": [
    "#take about 15mins\n",
    "top1_id = []\n",
    "top1_fre = []\n",
    "top2_id = []\n",
    "top2_fre = []\n",
    "a = 0\n",
    "for id in np.arange(1000)+1:\n",
    "    lens =len(data3.set_index('玩家id').loc[id].index)\n",
    "    for i in np.arange(lens)+1:\n",
    "        top1 = data3.set_index('玩家id').loc[id].iloc[:i,:]['计费点id'].mode().values[0]\n",
    "        freq1 = data3.set_index('玩家id').loc[id].iloc[:i,:]['计费点id'].value_counts(normalize=True).values[0]\n",
    "        tops_num = len(data3.set_index('玩家id').loc[id].iloc[:i,:]['计费点id'].value_counts(normalize=True).index)\n",
    "        \n",
    "        top1_id.append(top1)\n",
    "        top1_fre.append(freq1)\n",
    "        \n",
    "\n",
    "        if tops_num>=2:\n",
    "            \n",
    "            top2 = data3.set_index('玩家id').loc[id].iloc[:i,:]['计费点id'].value_counts(normalize=True).index[1]\n",
    "            freq2 = data3.set_index('玩家id').loc[id].iloc[:i,:]['计费点id'].value_counts(normalize=True).values[1]\n",
    "            top2_id.append(top2)\n",
    "            top2_fre.append(freq2)\n",
    "        else:\n",
    "            top2_id.append(a)\n",
    "            top2_fre.append(a)\n",
    "    print(id)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "data3['最高频计费点'] = np.array(top1_id)\n",
    "data3['最高频计费点fre'] = np.array(top1_fre)\n",
    "data3['第二高频计费点']=np.array(top2_id)\n",
    "data3['第二高频计费点fre']=np.array(top2_fre)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "data3.loc[data3['首次付费']==1,'最高频计费点']=0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "data3.to_excel('付费分析all.xlsx')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "data3 = pd.read_excel('付费分析all.xlsx')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 建模"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.preprocessing import OneHotEncoder\n",
    "from sklearn.metrics import classification_report\n",
    "from sklearn.model_selection import train_test_split\n",
    "from sklearn.ensemble import GradientBoostingClassifier\n",
    "from sklearn.linear_model import LogisticRegression\n",
    "from sklearn.tree import DecisionTreeClassifier\n",
    "from sklearn.ensemble import RandomForestClassifier\n",
    "from sklearn.naive_bayes import MultinomialNB\n",
    "from sklearn.svm import SVC"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "data3.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "data3.iloc[:,5]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "x = data3.iloc[:,6:]\n",
    "y = data3.iloc[:,5]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "x.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "xtrain,xtest,ytrain,ytest = train_test_split(x,y,random_state = 200)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## GBDT"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "GBDT = GradientBoostingClassifier().fit(xtrain,ytrain)\n",
    "print(classification_report(ytest,GBDT.predict(xtest)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "GBDT.score(xtest,ytest)\n",
    "#准确率"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.metrics import confusion_matrix\n",
    "confusion_matrix(ytest,GBDT.predict(xtest))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "[*zip(xtrain.columns,GBDT.feature_importances_)]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## DT"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "DT = DecisionTreeClassifier()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.model_selection import GridSearchCV\n",
    "#take about 20min\n",
    "parameters={'criterion':(\"gini\",\"entropy\")\n",
    "              ,\"max_depth\":[*range(1,30)]\n",
    "              ,'min_samples_leaf':[*range(1,50,5)]\n",
    "              ,'min_impurity_decrease':[*np.linspace(0,0.5,20)] #信息增益最小值\n",
    "             }\n",
    "clf = DecisionTreeClassifier(random_state=25)\n",
    "GS = GridSearchCV(clf,parameters,cv=10)\n",
    "GS.fit(xtrain,ytrain)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "GS.best_params_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "GS.best_score_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "DT = DecisionTreeClassifier(random_state=25\n",
    "                             ,criterion='gini'\n",
    "                             ,max_depth=4\n",
    "                             ,min_impurity_decrease=0\n",
    "                             ,min_samples_leaf=6\n",
    "                            ).fit(xtrain,ytrain)\n",
    "print(classification_report(ytest,DT.predict(xtest)))\n",
    "confusion_matrix(ytest,DT.predict(xtest))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "[*zip(xtrain.columns,DT.feature_importances_)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import graphviz\n",
    "from sklearn import tree\n",
    "dot_data = tree.export_graphviz(DT\n",
    "                                ,out_file = None\n",
    "                                ,feature_names= xtrain.columns\n",
    "                                ,class_names=['1','2','3']\n",
    "                                ,filled=True\n",
    "                                ,rounded=True\n",
    "                                )\n",
    "graph = graphviz.Source(dot_data) \n",
    "graph"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## XGB"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from xgboost import XGBClassifier"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "model = XGBClassifier(learning_rate=0.1,\n",
    "                      n_estimators=1000,         # 树的个数--1000棵树建立xgboost\n",
    "                      max_depth=6,               # 树的深度\n",
    "                      min_child_weight = 1,      # 叶子节点最小权重\n",
    "                       gamma=0.,                  # 惩罚项中叶子结点个数前的参数\n",
    "                       subsample=0.8,             # 随机选择80%样本建立决策树\n",
    "                       colsample_btree=0.8,       # 随机选择80%特征建立决策树\n",
    "                       objective='multi:softmax', # 指定损失函数\n",
    "                     scale_pos_weight=1,        # 解决样本个数不平衡的问题\n",
    "                     random_state=27            # 随机数\n",
    "                       )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "y[ytest.index]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "model.fit(xtrain,\n",
    "        y[ytrain.index],\n",
    "          eval_set = [(xtest,y[ytest.index])],\n",
    "          eval_metric = \"mlogloss\",\n",
    "           early_stopping_rounds = 10,\n",
    "           verbose = True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "model.score(xtest,y[ytest.index])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 总结\n",
    "# 首先拿到原始数据\n",
    "# 用5w2h分析方法构建（特征）指标体系\n",
    "# 找到计费点和每一个特征的关系 用BI画出计费点和特征的关系图表 形成一个报告\n",
    "# 用机器学习的算法建模 将提取的特征作为特征 将‘计费点’作为标签 直接预测\n",
    "# 使用模型后  看ARPPU APA 以及用户周期等指标有没有变好\n",
    "# 后续模型会继续更新"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {
    "height": "calc(100% - 180px)",
    "left": "10px",
    "top": "150px",
    "width": "364.878px"
   },
   "toc_section_display": true,
   "toc_window_display": true
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
